import { defineStore } from "pinia";
import { ref } from "vue";
import { useLoginAPI } from "@/api/login.js";

export const useUserInfoStore = defineStore('userInfo',
  () => {
    const userInfo = ref({})
    const updateUserInfo = async (data) => {
      const res = await useLoginAPI(data)
      userInfo.value = res.result
    }
    const removeUserInfo = () => {
      userInfo.value = {}
      localStorage.removeItem('userInfo')
    }

    return {
      userInfo,
      updateUserInfo,
      removeUserInfo
    }
  },
  {
    persist: true
  }
)
